package com.xja.git.controller;

import com.xja.git.entity.Gituser;
import com.xja.git.service.GitUserService;
import com.xja.git.utils.PageResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GitController {
    @Autowired
    private GitUserService gitUserService;
    @GetMapping("find")
    public String find(){
        return "第一个方法";
    }

    /**
     * 查询全部
     * @return
     */
    @GetMapping("selectAll")
    public PageResult selectAll(){
        List<Gituser> gitusers = gitUserService.selectAll();
      return   PageResult.success(null,gitusers);
    }

    /**
     * 删除
     * @return
     */
    @GetMapping("remove")
    public PageResult remove(){
        int n = gitUserService.remove(3);
        System.out.println(n);
        if (n==0){
            return PageResult.error("删除错误");
        }
        return   PageResult.success("删除成功",null);
    }
    @GetMapping("add")
    public PageResult add(Gituser gituser) {
        gituser.setName("马超");
        gituser.setPassword("111111");
        int i = gitUserService.addGituser(gituser);
        if (i > 0) {
            return PageResult.success("添加成功", null);
        } else {
            return PageResult.error("添加失败");
        }


    }
    @GetMapping("delete")
    public  PageResult delete(){
        return  PageResult.success("成功",null);
    }
}
